package com.fire.shop.controller;



import com.fire.common.controller.BaseController;
import com.fire.common.core.page.TableDataInfo;
import com.fire.common.domain.Result;
import com.fire.shop.domain.Device;
import com.fire.shop.service.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <h1>设备管理</h1>
 * */
@RestController
@RequestMapping("/device")
public class DeviceController extends BaseController {

    @Autowired
    private DeviceService deviceService;


    /**
     * <h2>
     *     查询所有device列表业务方法的url接口/device-list
     * </h2>
     * */
    @GetMapping("/device-list")
    public TableDataInfo deviceList(Device device)
    {
        startPage();
        List<Device> list = deviceService.queryAllDevice(device);
        return getDataTable(list);
    }

    /**
     * <h2>
     *     删除device业务方法的url接口/device-delete/{id}
     * </h2>
     * */
    @DeleteMapping("/device-delete/{id}")
    public Result deleteDevice(@PathVariable String id)
    {
        int rows = deviceService.deleteById(id);
        return rows > 0 ? Result.ok() : Result.err(500, "删除失败");
    }

    /**
    * <h2>
     *     更新device业务方法的url接口/device-update
    * </h2>
    * */
    @PutMapping("/device-update")
    public Result updateDevice(@RequestBody Device device)
    {
        int rows = deviceService.updateById(device);
        return rows > 0 ? Result.ok() : Result.err(500, "更新失败");
    }

    /**
     * <h2>
     *     新增device业务方法的url接口/device-add
     * </h2>
     * */
    @PostMapping("/device-add")
    public Result addDevice(@RequestBody Device device)
    {
        int rows = deviceService.insert(device);
        return rows > 0 ? Result.ok() : Result.err(500, "新增失败");
    }

    /**
     * <h2>
     *     更新device状态业务方法的url接口/device-status-update
     * </h2>
     * */
    @PutMapping("/device-status-update")
    public Result updateDeviceStatus(Device device)
    {
        int rows = deviceService.updateStatusById(device);
        return rows > 0 ? Result.ok() : Result.err(500, "更新失败");
    }

    /**
     * <h2>
     *     更新device服务时间业务方法的url接口/device-service-time-update
     * </h2>
     * */
    @PutMapping("/device-service-time-update")
    public Result updateDeviceServiceTime(Device device)
    {
        int rows = deviceService.updateServiceTimeById(device);
        return rows > 0 ? Result.ok() : Result.err(500, "更新失败");
    }

}
